package edu.zcmu.seckill.controller;


import edu.zcmu.seckill.response.R;
import edu.zcmu.seckill.service.SeckillOrderService;
import edu.zcmu.seckill.service.impl.SeckillOrderServiceImpl;
import edu.zcmu.seckill.vo.GenerateOrderVo;
import edu.zcmu.seckill.vo.SeckillOrderInfoVo;
import edu.zcmu.seckill.vo.SeckillOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 唐诗
 * @since 2022-02-22
 */
@RestController
@RequestMapping("/seckill/seckill-order")
public class SeckillOrderController {

    @Autowired
    SeckillOrderService seckillOrderService;

    /**
     * 压测
     * @param
     * @param request
     * @return
     */
    @PostMapping("/test")
    public R generateOrder(@RequestBody Map<String,String> map, HttpServletRequest request){
        String s = seckillOrderService.generateOrderTest(map.get("id"), request);
        return R.ok().data("data",s);
    }
    /**
     * 获取秒杀地址
     * @param map
     * @param request
     * @return
     */
    @PostMapping("/getSeckillPath")
    public R getSeckillPath(@RequestBody Map map, HttpServletRequest request){
        String path=seckillOrderService.getSeckillPath(Integer.valueOf(map.get("id").toString()),map.get("code").toString(),request);
        return R.ok().data("data",path);
    }

    /**
     * 生成订单
     * @param generateOrderVo
     * @param request
     * @return
     */
    @PostMapping("/generateOrder")
    public R generateOrder(@RequestBody GenerateOrderVo generateOrderVo,HttpServletRequest request){
        String s = seckillOrderService.generateOrder(generateOrderVo, request);
        return R.ok().data("data",s);
    }

    /**
     * 获取订单信息
     * @param vo
     * @return
     */
    @PostMapping("/querySeckillProductById")
    public R querySeckillProductById(@RequestBody SeckillOrderInfoVo vo,HttpServletRequest request){
        SeckillOrderVo seckillOrderVo=seckillOrderService.querySeckillProduct(vo,request);
        return R.ok().data("data",seckillOrderVo);
    }

}
